<?php
require_once  __DIR__ . '/includes/authenticate.php';

if (isset($_POST['playerID'])) {

	include_once './db_bb_connect.php'; 

	$playerID = $_POST['playerID'];

	$sql = "SELECT firstname, lastname 
			FROM users
			WHERE user_key = '$playerID'";

	$result=$db->query($sql);
	$row=$result->fetch_assoc();
	$firstname = $row['firstname'];
	$lastname = $row['lastname'];

?>

<br><br>
<div class="row">

<div class="col-md-6">

<div class="text-center"><h4>Add New Attention Point for <?= $firstname ?> <?= $lastname ?> </h4></div>

<form>

<input type="hidden" name="playerID" value="<?= $playerID ?>"/> 
    
    Category:
<select class="form-control" name="category">
         	<option value="" disabled="disabled" selected="selected">Select a category</option>
         	<option value="game">Game</option>
         	<option value="training">Training</option>
          	<option value="general">General</option>
</select>
<br><br>
Visibility:
<select class="form-control" name="visibility">
  <option value="no" selected="selected">No</option>
  <option value="yes">Yes</option>
</select>

<br><br>
 <textarea class="form-control" rows="4"  name="text"></textarea> 
<br><br>

	<button type="submit" class="btn btn-success"> Submit </button>
  </form>
</div>

</div>


<script type="text/javascript">
  
$("form").on("submit", function(event) {
    postData = $( this ).serialize();
    event.preventDefault();
    callAddPlayerNote(postData);
});


function callAddPlayerNote(e, postData){
  $.ajax({
  type: "POST",
  url: "./includes/handlers/playerpointsofattention_add_handler.php",
  data: this.postData,
  success: function(data) {
    $("#fullplayerprofile").html(data);
  },
  error: function (xhr, status, error) {
        alert(xhr.responseText); 
        }
  }); 

  e.preventDefault();
};

</script>

<?php } ?>